home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / plane arcade / planearcade.exe / tank3.bmp / light.cpp < prev    next >
C/C++ Source or Header  |  2002-10-29  |  4KB  |  177 lines

  1.  
  2. #include "main.h"
  3.  
  4.  
  5. //---------------------------------------------------------------------
  6. //Globalne PremennΘ
  7. //---------------------------------------------------------------------
  8.  
  9. //Light Manager
  10. LIGHTMANAGER LightManager;
  11.  
  12. //------------------------------------------------------------------
  13. // Name: LIGHTMANAGER()
  14. // Desc: Konstruktor
  15. //------------------------------------------------------------------
  16. LIGHTMANAGER::LIGHTMANAGER()
  17. {
  18.     Light = NULL;
  19.     D3DLight = NULL;
  20.     NumLights = 0;
  21. }
  22.  
  23. //------------------------------------------------------------------
  24. // Name: LIGHTMANAGER()
  25. // Desc: Destruktor
  26. //------------------------------------------------------------------
  27. LIGHTMANAGER::~LIGHTMANAGER()
  28. {
  29.  
  30.     //
  31.     if (Light !=NULL)
  32.         delete [] Light;
  33.     Light = NULL;
  34.  
  35.     //
  36.     if (D3DLight !=NULL)
  37.         delete [] D3DLight;
  38.     D3DLight = NULL;
  39.  
  40.     
  41. }
  42.  
  43. //------------------------------------------------------------------
  44. // Name: Initialize()
  45. // Desc: Maximalny pocet svetiel
  46. //------------------------------------------------------------------
  47. void LIGHTMANAGER::Initialize(int NLights)
  48. {
  49.  
  50.     //
  51.     Light = new LIGHT[NLights];
  52.     D3DLight = new D3DLIGHT9[NLights];
  53.     NumLights = 0;
  54.  
  55.  
  56.  
  57.  
  58. }
  59.  
  60. //------------------------------------------------------------------
  61. // Name: CleanUp()
  62. // Desc: Zresetuj svetla
  63. //------------------------------------------------------------------
  64. void LIGHTMANAGER::CleanUp()
  65. {
  66.     if (Light !=NULL)
  67.         delete [] Light;
  68.     Light = NULL;
  69.  
  70.     NumLights = 0;
  71.  
  72. }
  73.  
  74.  
  75. //------------------------------------------------------------------
  76. // Name: AddLightPoint
  77. // Desc: Pridaj bodove svetlo
  78. //------------------------------------------------------------------
  79. void LIGHTMANAGER::AddLightPoint(VECTOR3D Pos,COLOR Diffuse,
  80.                                     COLOR Ambient,
  81.                                     COLOR Specular,
  82.                                     float Atten,float Range)
  83. {
  84.  
  85.     Light[NumLights].Pos = Pos;
  86.  
  87.     Light[NumLights].Type = D3DLIGHT_POINT;
  88.     
  89.     Light[NumLights].Ambient  = Ambient;
  90.     Light[NumLights].Diffuse  = Diffuse;
  91.     Light[NumLights].Specular = Specular;
  92.  
  93.     Light[NumLights].Atten0 = Atten;
  94.     Light[NumLights].Range = Range;
  95.     Light[NumLights].Active = true;
  96.  
  97.  
  98.     NumLights++;
  99. }
  100.  
  101.  
  102. //------------------------------------------------------------------
  103. // Name: AddLightDir
  104. // Desc: pridaj smerove svetlo (slnko)
  105. //------------------------------------------------------------------
  106. void LIGHTMANAGER::AddLightDir(VECTOR3D Dir,COLOR Diffuse,
  107.                               COLOR Ambient,
  108.                               COLOR Specular)
  109. {
  110.     Light[NumLights].Dir = Dir;
  111.  
  112.     Light[NumLights].Type = D3DLIGHT_DIRECTIONAL;
  113.     
  114.     Light[NumLights].Ambient  = Ambient;
  115.     Light[NumLights].Diffuse  = Diffuse;
  116.     Light[NumLights].Specular = Specular;
  117.  
  118.     Light[NumLights].Active = true;    
  119.  
  120.     NumLights++;
  121. }
  122.  
  123. //------------------------------------------------------------------
  124. // Name: RefreshLights()
  125. // Desc: obnovi svetla
  126. //------------------------------------------------------------------
  127. void LIGHTMANAGER::RefreshLights()
  128. {
  129.  
  130.     for (int i=0;i<NumLights;i++)
  131.     {
  132.     if (Light[i].Active == true)
  133.     {
  134.         ZeroMemory( &D3DLight[i], sizeof(D3DLIGHT9) );
  135.         //ambient
  136.         D3DLight[i].Ambient.a = Light[i].Ambient.A;
  137.         D3DLight[i].Ambient.r = Light[i].Ambient.R;
  138.         D3DLight[i].Ambient.g = Light[i].Ambient.G;
  139.         D3DLight[i].Ambient.b = Light[i].Ambient.B;
  140.  
  141.         //Diffuse
  142.         D3DLight[i].Diffuse.a = Light[i].Diffuse.A;
  143.         D3DLight[i].Diffuse.r = Light[i].Diffuse.R;
  144.         D3DLight[i].Diffuse.g = Light[i].Diffuse.G;
  145.         D3DLight[i].Diffuse.b = Light[i].Diffuse.B;
  146.  
  147.         //Specular
  148.         D3DLight[i].Specular.a = Light[i].Specular.A;
  149.         D3DLight[i].Specular.r = Light[i].Specular.R;
  150.         D3DLight[i].Specular.g = Light[i].Specular.G;
  151.         D3DLight[i].Specular.b = Light[i].Specular.B;
  152.  
  153.         //vlastnosti
  154.         D3DLight[i].Direction.x = Light[i].Dir.X  ;
  155.         D3DLight[i].Direction.y = Light[i].Dir.Y  ;
  156.         D3DLight[i].Direction.z = Light[i].Dir.Z  ;
  157.         
  158.         D3DLight[i].Attenuation0 = Light[i].Atten0 ;
  159.  
  160.         D3DLight[i].Position.x = Light[i].Pos.X; 
  161.         D3DLight[i].Position.y = Light[i].Pos.Y;
  162.         D3DLight[i].Position.z = Light[i].Pos.Z;
  163.  
  164.         D3DLight[i].Type  =  Light[i].Type;
  165.  
  166.         D3DLight[i].Range = Light[i].Range  ;
  167.  
  168.         g_pd3dDevice->SetLight( i, &D3DLight[i] );
  169.         g_pd3dDevice->LightEnable( i, TRUE );
  170.         
  171.     }
  172.     }
  173.  
  174.     
  175. }
  176.  
  177.